package com.cx.jvm;

import sun.net.spi.nameservice.dns.DNSNameService;

import java.io.File;
import java.util.StringTokenizer;

/**
 * @Author: songyahui
 * @Date: 2020/7/11 13:19
 * @Version 1.0
 */
public class ClassLoaderDemo {
    public static void main(String[] args) throws InterruptedException {
        getObjectClassLoader();
        Stringd.test();
        System.out.println("自定义的String 的加载器：" + Stringd.class.getClassLoader());
    }

    private static void getObjectClassLoader() {
        ClassLoader c1 = Object.class.getClassLoader();
        //根类加载器打印结果为 null
        System.out.println(c1);

        System.out.println("dnsns加载器：" + DNSNameService.class.getClassLoader());
    }

    private static File[] getExtDirs() {
        java.lang.String s = System.getProperty("java.ext.dirs");
        File[] dirs;
        if (s != null) {
            StringTokenizer st = new StringTokenizer(s, File.pathSeparator);
            int count = st.countTokens();
            dirs = new File[count];
            for (int i = 0; i < count; i++) {
                dirs[i] = new File(st.nextToken());
            }
        } else {
            dirs = new File[0];
        }
        return dirs;
    }
}

class Stringd {
    public static void test() {
        String s1 = "abc";
        String s2 = "a";
        String s3 = "bc";
        String s4 = s2 + s3;
        String s5 = "a" + "bc";
        System.out.println(s1 == s4);
        System.out.println(s1 == s5);
        String s6 = new String("a") + new String("bc");
        String s7 = s6.intern();
        System.out.println(s6 == s1);
        System.out.println(s7 == s1);
        System.out.println("test to classloader");
    }
}


